package com.cmse.service.impl;

import java.util.List;

import com.cmse.persistence.dao.IArticalCommentDao;
import com.cmse.persistence.dao.IArticalDao;
import com.cmse.persistence.domain.Artical;
import com.cmse.persistence.domain.ArticalComment;
import com.cmse.persistence.enmu.ArticalCategory;
import com.cmse.persistence.enmu.FetchOrderType;
import com.cmse.persistence.enmu.VerifyType;
import com.cmse.service.IArticalService;

/**
 * @author wulibin, exceptsky@gmail.com, 2012-3-15 下午1:43:26
 * 
 */
public class ArticalService extends BaseService<Artical> implements IArticalService{
	private IArticalDao articalDao;
	private IArticalCommentDao commentDao;
	
	@Override
	public void addComment(long aid, ArticalComment comment) {
		comment.setArtical(get(aid));
		commentDao.add(comment);
	}

	@Override
	public long getCommentCount(long aid, VerifyType verifyType) {
		return commentDao.getCountOfObj(aid, verifyType);
	}
	
	@Override
	public List<Artical> getPage(int page, ArticalCategory category, FetchOrderType orderType){
		Artical expArtical = new Artical();
		expArtical.setCategory(category.toString());
		return this.getByCondition(expArtical, page, orderType);
	}

	@Override
	public List<ArticalComment> getComments(long aid, int page, VerifyType verifyType) {
		return commentDao.getOfObj(aid, pageLength*page, pageLength, verifyType, FetchOrderType.CREATE_DESC);
	}
	
	@Override
	public long getCountByCategory(ArticalCategory category) {
		Artical expArtical = new Artical();
		expArtical.setCategory(category.toString());
		return this.getCountByCondition(expArtical);
	}
	
	public void setCommentDao(IArticalCommentDao commentDao) {
		this.commentDao = commentDao;
	}

	public void setArticalDao(IArticalDao articalDao) {
		this.articalDao = articalDao;
		this.setDao(this.articalDao);
	}
}
